function [tables, actions, scores, pieces, moveRatings] = ...
            assignTableActionPairs(maxMoves, initTables, initActions, ...
                        initScores, initPieces, initMoveRatings)

tableHeight = 12;
tableWidth = 6;
pieceNum = 7;
                    
tables = cell(maxMoves, 1);
actions = zeros(maxMoves, 1);
scores = zeros(maxMoves, 1);
pieces = zeros(maxMoves, 1);
moveRatings = zeros(maxMoves, 1);

if exist('initTables', 'var')
    initMove = length(initTables);
    gameNumber = length(initScores);
    table = initTables{end};
    piece = initPieces(end);
    
    tables(1 : initMove) = initTables;
    actions(1 : initMove) = initActions;
    pieces(1 : initMove) = initPieces;
    moveRatings(1 : initMove) = initMoveRatings;
    scores(1 : gameNumber) = initScores;
else
    initMove = 1;
    gameNumber = 1;
    table = zeros(tableHeight, tableWidth);
    piece = randi(pieceNum);
end

dispTable(table);
disp(scores(gameNumber));

exit = false;

move = initMove;
while move <= maxMoves
    pieces(move) = piece;
    tetromino = generateTetromino(piece, 1);
    legalMoves = getLegalMoves(piece);
    ok = false;

    disp(['Potez: ', num2str(move)]);
    while ok ~= 1
        disp(tetromino);
    
        while 1
            rotation = input('Rotacija: ');
            position = input('Pozicija: ');
            
            posRot = [position; rotation];
            if sum(size(posRot) ~= [2 1]) > 0
                continue;
            end
            
            posRot = posRot(:, ones(size(legalMoves, 2), 1));
        
            tempAction = find(sum(legalMoves == posRot) == 2);
        
            if length(tempAction) == 1
                break;
            end
        end
        
        tables{move} = table;
        actions(move) = tempAction;
    
        [newTable, score, scaledScore] = performMove(table, piece, position, rotation);
        
        moveRatings(move) = scaledScore;
    
        if score == -800
            newTable = zeros(tableHeight, tableWidth);
            disp('Nova igra');
        else
            scores(gameNumber) = scores(gameNumber) + score;
        end
    
        dispTable(newTable);
        disp(scores(gameNumber));
        
        ok = input('Ok? ');
        
        if ok == -100
            exit = 1;
            break;
        elseif ok == 1
            table = newTable;
            
            if score == -800 && move < maxMoves
                gameNumber = gameNumber + 1;
            end
        elseif ok == -200
            move = move - 1;
            table = zeros(tableHeight, tableWidth);
            ok = 1;
            
            if move < maxMoves
                gameNumber = gameNumber + 1;
            end
            dispTable(table);
            disp(scores(gameNumber));
        else
            dispTable(table);
            disp(scores(gameNumber));
        end
    end
    
    if exit
        break;
    end
    
    piece = randi(pieceNum);
    move = move + 1;
end

move = move - 1;
tables = tables(1 : move);
actions = actions(1 : move);
pieces = pieces(1 : move);
moveRatings = moveRatings(1 : move);
scores = scores(1 : gameNumber);
